﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MLopez.BizVal.GUI.Controls
{
    public partial class CrearJerarquia : ChildWindow
    {
        public int Niveles { get; set; }
        public int GranularidadMin { get; set; }
        public string Nombre { get; set; }

        public CrearJerarquia()
        {
            InitializeComponent();
            lbError.Visibility = System.Windows.Visibility.Collapsed;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.Nombre = tbNombre.Text.Trim();
                this.Niveles = int.Parse(tbNiveles.Text);
                this.GranularidadMin = int.Parse(tbGranularidad.Text);
                if (this.Niveles <= 0)
                {
                    lbError.Content = "El número de niveles ha de ser mayor que 0";
                    lbError.Visibility = System.Windows.Visibility.Visible;
                }
                else if (this.GranularidadMin <= 1)
                {
                    lbError.Content = "La granularidad mínima ha de mayor que 1";
                    lbError.Visibility = System.Windows.Visibility.Visible;
                }
                else if (this.Nombre == string.Empty)
                {
                    lbError.Content = "Es obligatorio introducir un nombre";
                    lbError.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    this.DialogResult = true;
                }
            }
            catch (FormatException)
            {
                lbError.Content = "Introduzca solo valores numéricos";
                lbError.Visibility = System.Windows.Visibility.Visible;                
            }
            
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

